{layout name="public/layout" /}

        {include file='yxnavbar'}
<style>
.table td span{display:inline-block;margin-top:4px;}
.table td input{margin-bottom:0;}
</style>
{if $op == 'addbank'}
<div class="clearfix">
<form class="form-horizontal form" action="" method="post" encgiftgroup="multipart/form-data" onsubmit="return check()">
    <div class="panel panel-default">
        <div class="panel-heading">二维码添加/修改{$qrlist['id']}</div>
        <div class="panel-body">
                <input type="hidden" name="id" value="{$qrlist['id']}">
                <div class="form-group">
                    <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label">显示顺序</label>
                    <div class="col-sm-8 col-xs-12">
                        <input type="text" class="form-control" placeholder="" name="displayorder" value="{$qrlist['displayorder']}">
                    </div>
                </div>
                {if (!empty($id)) }
                <div class="form-group">
                    <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label">二维码</label>
                    <div class="col-sm-8 col-xs-12">
                       {php echo view_form_field_image('qrimg',$qrlist['qrimg']);}
                       <span class="help-block">{if $isold==true}已禁用,{/if}活动页面最上方的图片，一般为宣传主图</span>
                    </div>
                </div> 
                {else}
               <div class="form-group">
                    <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label">二维码</label>
                    <div class="col-sm-8 col-xs-12">
                       {php echo view_form_field_multi_image('qrimg');}
                       <span class="help-block">可以一次上传多张，批量添加</span>
                    </div>
                </div>
                {/if}
                <div class="form-group">
                    <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label"><span style='color:red'>*</span>数量</label>
                    <div class="col-sm-8 col-xs-12">
                        <input type="text" class="form-control" placeholder="" name="qrnum" value="{$qrlist['qrnum']}">
                    </div>
                </div>
                {if (!empty($id)) }
                <div class="form-group">
                    <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label"><span style='color:red'>*</span>已用数量</label>
                    <div class="col-sm-8 col-xs-12">
                        <input type="text" class="form-control" placeholder="" name="usercount" value="{$qrlist['usercount']}">
                    </div>
                </div>
                {/if}
                <div class="form-group">
                    <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label">是否启用</label>
                    <div class="col-sm-8 col-xs-12">
                    <label class="checkbox">
                      <input type="checkbox" name="state" value="1" {if $qrlist['state'] != 0}checked="checked"{/if}>勾选则表示启用
                    </label>
                     </div>
                </div> 
                                           
        </div>      
    </div>
    <div class="form-group">
        <div class="col-sm-12" style="text-align: right;">
            {if !empty($qrlist['addtime'])}
            {php  echo "操作员：" . $qrlist['user'] . " 操作IP：" . $qrlist['ip'] ;}
            {php  echo " 操作时间：" .date('Y-m-d H:i:s',$qrlist['addtime']);}
            {/if}
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-12">
            <input name="submit" type="submit" value="提交" class="btn btn-primary col-lg-1">
            <input type="hidden" name="__token__" value="{$Request.token}" />
        </div>
    </div>
</form>
</div>
{elseif $op == 'display'}
<div class="main">
  <div class="panel panel-default">
        <div class="panel-heading">
                    <div style="text-align:right;" >
                      <a class="btn btn-info btn-sm "href="{php echo createWebUrl($do, array('op' => 'addbank'));}" title="添加"><i class="icon-edit"></i>添加二维码</a>
                    </div>
        </div>
        <div class="panel-body table-responsive">
            <table class="table table-hover">
                <thead class="navbar-inner">
                    <tr>
                        <th >ID</th>
                        <th >顺序</th>
                        <th >图片</th>
                        <th >数量</th>
                        <th >已用数量</th>
                        <th >状态</th>
                        <th >操作时间</th>
                        <th style="width:180px; text-align:right;">操作</th>
                    </tr>
                </thead>
                <tbody>
                {loop $list $index $item}
                  <tr> 
                    <td>{php echo $item['id'];}</td>
                    <td>{$item['displayorder']}</td>
                    <td> <img src="{$item['qrimg']}" width="40px" style="bsection-radius: 3px;"></td>
                    <td>{$item['qrnum']}</td>
                    <td>{$item['usercount']}</td>
                    <td><input type="checkbox" name="status[]" data-id="{$item['id']}" value="{$item['state']}" class="hidden" {if intval($item['state'])==1} checked="checked" {/if}/></td>
                    <td>{php echo date("Y-m-d H:i:s",$item['addtime']);}</td>
                    <td style="text-align:right;">
                    {if $item['usercount']>0}
                        <a class="btn btn-success btn-sm" href="{php echo createWebUrl('record', array('themeid' => $themeid,'qrimgid' =>$item['id']));}" title="使用"><i class="icon-edit"></i>使用明细</a>
                    {/if}
                      <a class="btn btn-success btn-sm" href="{php echo createWebUrl($do, array('op' => 'addbank','id' =>$item['id']));}" title="修改"><i class="icon-edit"></i>修改</a>
                    </td>
                </tr>
                {/loop}
            </tbody>
            </table>
        </div>
        {$pager}

                    
    </div>
    </div>
{/if}

<script type="text/javascript">
    $(function(){
        $('.app-preview').click(function(){
            return false;
        });
        require(['underscore', 'bootstrap.switch'], function() {
            $(":checkbox[name='status[]']").bootstrapSwitch();
            $(':checkbox').on('switchChange.bootstrapSwitch', function(e, state){
                $this = $(this);
                var id = $(this).data('id');
                var status = this.checked ? 1 : 0;
                $.post("{php echo createWebUrl($do, array('op' => 'status'));}", {status:status,id: id}, function(resp){
                    resp = $.parseJSON(resp);
                    if(resp.message.errno != 0) {
                        layer.msg('操作失败, 请稍后重试');
                    } else {
                        layer.msg('操作成功');
                    }
                });
            });     
            
        });
    });
</script>
<script type="text/javascript">
    function check(){
        if($.trim($(':text[name="qrnum"]').val()) == '') {
            alert('请输入数量');
            return false;
        }

    }
</script>
